package com.nefu.huiyi.result;

import lombok.Data;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.io.Serializable;
import java.util.Date;

@Data
public class HttpResult<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    private Date time;



    public static <T> HttpResult<T> success(T data) {
        HttpResult<T> result = new HttpResult<>();
        result.setCode(RespCode.SUCCESS.getCode());
        result.setMsg(RespCode.SUCCESS.getMsg());
        result.setData(data);
        result.setTime(new Date());
        return result;
    }

    public static <T> HttpResult<T> failed(String msg) {
        HttpResult<T> result = new HttpResult<>();
        result.setCode(RespCode.FAILED.getCode());
        result.setMsg(msg);
        result.setData(null);
        result.setTime(new Date());
        return result;
    }
}